{% extends "base.html" %}
{% block content %}
<h1>All inclusive</h1> 
<p>
  This page use a view with all options introduced so far, a easy
  sum-up of all preceding examples
</p>
<p>
  We consequently have statics vars, variables passed in URL and
  others built at runtime.
</p>
<ul>
<li><strong>chapter (class var)</strong>: <code>{{ chapter }}</code></li>
<li><strong>time (instance var)</strong>: <code>{{ time }}</code></li>
<li><strong>first URL kwarg</strong>: <code>{{ kwarg1 }}</code></li>
<li><strong>second URL kwarg</strong>: <code>{{ kwarg2 }}</code></li>
<li><strong>IP (built var)</strong>: <code>{{ ip }}</code></li>
</ul>
<div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">obviews.views</span> <span class="kn">import</span> <span class="n">View</span><span class="p">,</span> <span class="n">CutResponse</span>

<span class="c"># All inclusive</span>
<span class="k">class</span> <span class="nc">AllView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
    <span class="n">template_name</span> <span class="o">=</span> <span class="s">&quot;all.html&quot;</span>
    <span class="n">login_required</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="n">defaults</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;chapter&quot;</span><span class="p">:</span> <span class="s">&quot;all inclusive&quot;</span><span class="p">}</span>
    <span class="n">response_builder</span> <span class="o">=</span> <span class="n">HttpResponse</span>

    <span class="k">def</span> <span class="nf">build_params</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">kwarg1</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">kwarg2</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="n">params</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">AllView</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">build_params</span><span class="p">(</span>
            <span class="n">request</span><span class="p">,</span> <span class="n">kwarg1</span><span class="o">=</span><span class="n">kwarg1</span><span class="p">,</span> <span class="n">kwarg2</span><span class="o">=</span><span class="n">kwarg2</span><span class="p">)</span>
        <span class="n">params</span><span class="p">[</span><span class="s">&quot;ip&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">META</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;IP&quot;</span><span class="p">,</span> <span class="s">&quot;ip not found&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">params</span>

<span class="n">urlpatterns</span> <span class="o">=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>
    <span class="c"># all inclusive: all options and settings available</span>
    <span class="p">(</span><span class="s">&#39;^all/(?P&lt;kwarg1&gt;\w+)/(?P&lt;kwarg2&gt;\w+)/$&#39;</span><span class="p">,</span> <span class="n">AllView</span><span class="p">(</span><span class="n">time</span><span class="o">=</span><span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">())),</span>
<span class="p">)</span>
</pre></div>
<p>
  Ok, you are done with basic views... you now may have a break... or
  continue to <a href="/form/simplest/">FormViews</a>...
</p>
{% endblock %}
